import Vue from 'vue'
import './cube-ui'

import App from './App.vue'
import router from './router'
import store from './store'
import 'amfe-flexible'
// 引入axios
import axios from 'axios'

import setAxios from './setAxios';
setAxios()

Vue.prototype.$http=axios

Vue.config.productionTip = false

// 路由导航守卫
router.beforeEach((to,from,next)=>{
  store.commit('setToken',localStorage.getItem('token'))
  if(to.meta.requireAuth){
    if(store.state.token){
      next()
    }else{
      next({
        path:'/login',
        query:{redirect:to.fullPath}
      })
    }
  }else{
    next()
  }
})

new Vue({
  router,
  store,
  render: h => h(App)
}).$mount('#app')
